package imoney.client.gwt;

import java.util.logging.Logger;

import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.Widget;

/**
 * A class containing some static methods
 * @author Arnaud PELOQUIN
 *
 */
public class GwtUtils {
	private static final Logger log = Logger.getLogger(GwtUtils.class.getName());
	
	public static void redirect(String url) {
		log.info("redirecting to: "+url);
		redir(url);
	}
	
	/**
	 * Native method redirecting the browser to given URL.
	 * @param url
	 */
	private static native void redir(String url)/*-{
	      $wnd.location = url;
	}-*/;
		
	/**
	 * Search for the given widget in the given row of the table.
	 * Returns the position of the widget if found, -1 otherwise.
	 * @param table : the table to search in
	 * @param wdgt : the widget to search for
	 * @param row : the row of the table to search in
	 * @return position : the position of widget, or -1 if not found.
	 */
	public static int getWidgetCol(FlexTable table, Widget wdgt, int row) {
		for (int col=0; col<table.getCellCount(row); col++) {
			if(table.getWidget(row, col).equals(wdgt)) {
				return col;
			}
		}
		return -1;
	}
}
